package com.example.bbs.domain.entity;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import org.springframework.data.annotation.Id;

import javax.validation.constraints.NotBlank;
import java.util.Date;
import java.util.Map;

@Data
public class Post {
    @Id
    @TableId(type = IdType.AUTO)
    private Integer id;
    private String postId;
    private String userId;
    private Integer tagId;
    @NotBlank(message = "标题不能为空！")
    private String title;
    @NotBlank(message = "内容不能为空！")
    private String content;
    private Integer commentCount;
    private Integer likeCount;
    private Integer type;
    private Integer status;
    private Date createTime;
    private Date updateTime;
    private Double score;
    private Integer viewCount;


    private static Post parseMap() {
        return parseMap();
    }


    /**
     * 将map格式的对象数据转化为实体对象
     * @param entries
     * @return
     */
    public static Post parseMap(Map<String, Object> entries) {
        return JSONObject.parseObject(JSONObject.toJSONString(entries), Post.class);
    }

    /**
     * 将实体对象数据转化为map格式的数据
     * @param post
     * @return
     */
    public static Map<String, Object> parseEntry(Post post) {
        return JSONObject.parseObject(JSONObject.toJSONString(post), Map.class);
    }




}
